package com.stenio.fancat.controller.behavior;

import com.stenio.fancat.controller.Result;
import com.stenio.fancat.exception.FanCatException;
import com.stenio.fancat.form.user.UserRelationshipForm;
import com.stenio.fancat.service.behavior.BehaviorShowService;
import com.stenio.fancat.vo.BehaviorVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 首页模板展示
 */
@RestController
@RequestMapping("behavior")
public class BehaviorShowController {

    @Autowired
    private BehaviorShowService behaviorShowService;

    /**
     * 展示首页任务列表
     * @param userRelationshipForm
     * @return
     */
    @PostMapping(value="selectBehaviorList",produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<List<BehaviorVO>> selectBehaviorList(@RequestBody(required = false) UserRelationshipForm userRelationshipForm){
        Result<List<BehaviorVO>> result = new Result<>();
        List<BehaviorVO> page = null;
        try {
            page = behaviorShowService.selectBehaviorList(userRelationshipForm);
        } catch (FanCatException e) {
            result.setMsg(e.getMsg());
            result.setErrorCode(e.getErrorCode());
            result.setFlag(Result.FLAG.failure);
            return result;
        }
        result.setFlag(Result.FLAG.success);
        result.setData(page);

        return result;
    }

}
